using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Collections.Generic;
using System.Drawing;

public class ResponseType : IComparable<ResponseType> {
  private string m_Name;
  private bool m_IsDefault;
  private Color m_Color;
  private int m_BitFlag;
  private int m_Index;
  private string m_TextColor;

  public string Name {
    get { return m_Name; }
  }

  public Color Color {
    get { return m_Color; }
  }

  public string HtmlColor {
    get { return ColorTranslator.ToHtml(m_Color); }
  }

  public string TextColor {
    get { return m_TextColor; }
  }

  public int BitFlag {
    get { return m_BitFlag; }
  }

  public int Index {
    get { return m_Index; }
  }

  public bool IsDefault {
    get { return m_IsDefault; }
  }

  public static ResponseType NoResponse;   
  public static ResponseType NotInterested;
  public static ResponseType Interested;
  public static ResponseType ContactLater;
  public static ResponseType Default;
  public static List<ResponseType> Responses = new List<ResponseType>();

  static ResponseType() {
    NoResponse = new ResponseType(1, 0, "no response", Color.Gray, "808080", true);
    NotInterested = new ResponseType(2, 1, "not interested", Color.Red, "ff0000", false);
    Interested = new ResponseType(4, 2, "interested", Color.Green, "00ff00", false);
    ContactLater = new ResponseType(8, 3, "contact later", Color.Blue, "0000ff", false);
    Default = NoResponse;

    Responses.AddRange(new ResponseType[] { NoResponse, NotInterested, Interested, ContactLater });
  }

  public static ResponseType Parse(string text) {
    foreach (ResponseType responseType in Responses) {
      if (responseType.Name == text)
        return responseType;
    }
    return Default;
  }

  public static ResponseType GetResponseType(int index) {
    foreach (ResponseType responseType in Responses) {
      if (responseType.Index == index)
        return responseType;
    }
    return null;
  }

  private ResponseType(int bitFlag, int index, string name, Color color, string textColor, bool isDefault) {
    m_BitFlag = bitFlag;
    m_Name = name;
    m_Color = color;
    m_TextColor = textColor;
    m_IsDefault = isDefault;
    m_Index = index;
  }

  #region IComparable<ResponseType> Members

  public int CompareTo(ResponseType other) {
    if (other == null)
      throw new ArgumentNullException("other");
    return m_Index.CompareTo(other.m_Index);
  }

  #endregion
}
